﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MethodWorx.CMS.UI.Application.ActionResults
{
    public class AppJavaScriptResult : ContentResult
    {
        private string javaScript;
        private List<AppJavaScriptResult> results = new List<AppJavaScriptResult>();

        public AppJavaScriptResult(string javaScript)
        {
            this.javaScript = javaScript; 
            this.Content = "<script language=\"javascript\" src=\"/scripts/app.js\"></script><script language=\"javascript\">" + javaScript + "</script>";
            this.results.Add(this);
        }

        public AppJavaScriptResult And(AppJavaScriptResult result)
        {
            this.javaScript += result.javaScript;
            this.Content = "<script language=\"javascript\" src=\"/scripts/app.js\"></script><script language=\"javascript\">" + javaScript + "</script>";
            this.results.Add(result);
            return this;
        }

        public IEnumerable<AppJavaScriptResult> Results { get { return this.results.AsReadOnly(); } }
    }
}